<template>
	<div class="page-index pr">
		<div class="pa loadingInfo flex3" v-if='isLoading'>
			<van-loading size="24px">加载中...</van-loading>
		</div>
		<div class="hd">
			<div class="info">
				<div class="info-hd">付款给</div>
				<div class="info-bd">山西天慈医院</div>
			</div>
			<div class="info-icon">
				<img class="info-icon-img" src="@/assets/img/info-icon.png" alt="">
			</div>
			<div class="bg"></div>
		</div>
		<div class="bd">
			<div class="box">
				<div class="box-hd">
					<div class="box-hd-label">费用总额</div>
					<div class="box-hd-value">{{orderInfo.feeSumamt||0}}元</div>
				</div>
				<div class="box-bd">
					<div class="box-item">
						<div class="box-bd-label">医保基金支付</div>
						<div class="box-bd-value">{{orderInfo.fundPay||0}}元</div>
					</div>
					<div class="box-item">
						<div class="box-bd-label">个人帐户支付</div>
						<div class="box-bd-value">{{orderInfo.psnAcctPay||0}}元</div>
					</div>
					<!-- <div class="box-item">
						<div class="box-bd-label">其他抵扣金额</div>
						<div class="box-bd-value">233元</div>
					</div> -->
				</div>
				<div class="box-ft">
					<div class="box-ft-label">现金支付</div>
					<div class="box-ft-value">{{orderInfo.ownPayAmt||0}}元</div>
				</div>
				<!-- <div class="box-append" @click="handleActionsheet">
					查看明细
				</div> -->
			</div>
			<div class="bd-append">
				<i class="bd-append-icon"></i>
				<div class="bd-append-text">医保移动支付</div>
			</div>
			<div v-if='!isLoading' class="box-append" @click="toPayBack">
				<!-- (retCode==150402||retCode==150403)?'上一页': -->
				返回{{formType==0?'挂号详情':'门诊缴费'}}
			</div>
			<!-- <div>
				哈哈：{{JSON.stringify(rgstInfo)}}
			</div> -->
		</div>
		<div class="ft">
			<div class="pay">
				<div class="pay-label">您还需支付：</div>
				<div class="pay-value">¥{{orderInfo.ownPayAmt||0}}</div>
			</div>
			<div class="btn" @click="payOrdId==''?'':toPays()" :class="payOrdId==''?'noBtns':''">去支付</div>
		</div>

	</div>
</template>

<script>
	import {
		mapGetters,
		mapState
	} from 'vuex';
	export default {
		name: 'PageIndex',
		data() {
			return {
				retCode: '',
				authCode: '',
				payOrdId: '',
				orderInfo: {},
				formType:0,//0--正常，1--门诊缴费
				isLoading:true
			}
		},
		computed: {
			...mapState({
				numInfo: 'numInfo',
				rgst_no: 'rgst_no',
				rgstInfo: 'rgstInfo'
			})
		},
		created() {
		   let that=this 
			// 获取地址参数
			console.log(location.search, 'location.search-----------医保')
			const params = new URLSearchParams(location.search);
			this.retCode = params.get('retCode');
			this.authCode = params.get('authCode');
			console.log(this.retCode, 'retCode')
			console.log(this.authCode, '旧的authCode')
			console.log(this.rgstInfo,'this.rgstInfo')
			if(this.rgstInfo&&this.rgstInfo.pid){
				this.formType=0
			}else{
				this.formType=1
			}
			if(that.retCode==150402){
				that.$toast('医保卡未激活！')
				that.isLoading=false
				setTimeout(()=>{
					that.$router.push({
						path: '/intro'
					})
				},1000)
				return
			}
			if(that.retCode==150403){
				that.$toast('用户未授权！')
				that.isLoading=false
				setTimeout(()=>{
					that.toPayBack()
				},1000)
				return
			}
			if(this.rgstInfo&&this.rgstInfo.pid){
				this.formType=0
				this.getInit()
			}else{
				this.formType=1
				this.doorgetInit()
			}
		},
		methods: {
			getInit() {
				
				console.log(this.rgst_no, '订单编号-----')
				let that = this
				let url = '/api/med/index/' + this.rgst_no + '?retCode=' + this.retCode + '&authCode=' + this.authCode;
				this.$axios.get(url).then(res => {
					console.log(res, '医保信息')
					if(res.data){
						that.orderInfo = res.data
						that.payOrdId = res.data.payOrdId
						that.isLoading=false
					}else{
						that.isLoading=false
					}
				})
			},
			doorgetInit() {
				
				// /api/med/pay_receipt?retCode=xxxx&authCode=xxx&receipt_no=xxx
				console.log(this.rgst_no, '门诊订单编号-----')
				let that = this
				let url = '/api/med/pay_receipt?retCode=' + this.retCode + '&authCode=' + this.authCode+'&receipt_no='+this.rgst_no;
				
				this.$axios.get(url).then(res => {
					console.log(res, '医保信息')
					if(res.data){
						that.orderInfo = res.data
						that.payOrdId = res.data.payOrdId
						that.isLoading=false
					}else{
						that.isLoading=false
					}
				})
			},
			//去支付
			toPays() {
				let that = this
				let url = '/api/med/place_yb_order?payOrdId=' + this.payOrdId;
				this.$axios.get(url).then(res => {
					console.log(res, '医保支付信息')
					var payUrl = res.pay_url
					location.href = payUrl
				}).catch(err => {

				});
			},
			
			toPayBack(){
				if(this.formType==0){//正常缴费
					this.$router.push({
						path: '/registerShow',
						query: {
							showtype: 'info',
							rgst_no: this.rgstInfo.rgst_no,
							pid: this.rgstInfo.pid
						},
					})
				}else{//门诊缴费
					this.$router.replace("/pay")
				}
				
			},
			handleActionsheet() {
				// this.actionsheetVisible = !this.actionsheetVisible;
			}
		}
	}
</script>

<style lang="less" scoped>
	.loadingInfo{
		width: 100%;
		top:250px;
		left:0px;
		z-index: 99;
	}
	.page-index {
		display: flex;
		flex-direction: column;
		min-height: 100vh;
	}

	.hd {
		position: relative;
		display: flex;
		justify-content: space-between;
		align-items: flex-end;
		color: #fff;
		padding: 32px 20px 20px 20px;
		box-sizing: border-box;
	}

	.bg {
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		height: 170px;
		background-color: #3EC5DB;
		border-radius: 0 0 30px 30px;
		z-index: 0;
	}

	.info {
		position: relative;
		z-index: 1;
		color: #fff;
	}

	.info-hd {
		font-size: 14px;
		line-height: 20px;
		color: rgba(255, 255, 255, 0.6);
	}

	.info-bd {
		font-size: 18px;
		line-height: 25px;
		margin-top: 3px;
		font-weight: bold;
	}

	.info-icon {
		position: relative;
		z-index: 1;
		width: 40px;
		height: 40px;
	}

	.info-icon-img {
		display: block;
		width: 100%;
		height: 100%;
	}

	.bd {
		flex: 1;
		position: relative;
		z-index: 1;
		border: none;
	}

	.box {
		border-radius: 8px;
		background-color: #fff;
		margin: 0 20px;
		padding: 0 20px;
		padding-bottom: 17px;
		box-shadow: 0 3px 10px #E6E6E6;
	}

	.box-hd {
		position: relative;
		display: flex;
		justify-content: space-between;
		padding: 24px 0 18px;
		color: #606266;
	}

	.box-hd:before {
		content: '';
		position: absolute;
		left: -8px;
		bottom: 0;
		right: -8px;
		border-bottom: 1px dashed #D8D8D8;
		transform: scaleY(0.5);
	}

	.box-hd-label {
		font-weight: bold;
	}

	.box-hd-value {
		font-weight: bold;
	}

	.box-bd {
		padding-top: 19px;
	}

	.box-item {
		display: flex;
		justify-content: space-between;
		color: #909399;
		font-size: 14px;
		line-height: 20px;
		padding-bottom: 10px;
	}

	.box-item:last-child {
		padding-bottom: 0;
	}

	.box-ft {
		display: flex;
		justify-content: space-between;
		padding-top: 20px;
		padding-bottom: 17px;
		font-size: 16px;
		color: #3EC5DB;
	}

	.box-ft-label {
		font-weight: bold;
	}

	.box-ft-value {
		font-weight: bold;
	}

	.box-append {
		position: relative;
		font-size: 14px;
		line-height: 20px;
		color: #606266;
		text-align: center;
		padding: 20px 0 3px;
	}

	.box-append:before {
		content: '';
		position: absolute;
		left: -8px;
		top: 0;
		right: -8px;
		/* border-top: 1px dashed #D8D8D8; */
		transform: scaleY(0.5);
	}

	.bd-append {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 32px;
		margin-bottom: 32px;
	}

	.bd-append-icon {
		display: block;
		width: 40px;
		height: 12px;
		background: url('../../../assets/img/medical-logo.png') center center no-repeat;
		background-size: 100% 100%;
		margin-right: 8px;
	}

	.bd-append-text {
		font-size: 14px;
		line-height: 20px;
		color: #909399;
		font-weight: bold;
	}

	.ft {
		position: relative;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-top: 14px;
		padding-left: 16px;
		padding-right: 16px;
		padding-bottom: calc(14px + constant(safe-area-inset-bottom));
		padding-bottom: calc(14px + env(safe-area-inset-bottom));
	}

	.pay {
		display: flex;
	}

	.pay-label {
		font-size: 16px;
		line-height: 24px;
		color: rgba(0, 0, 0, 0.6);
		margin-right: 5px;
	}

	.pay-value {
		font-size: 22px;
		line-height: 24px;
		color: #3EC5DB;
		font-weight: bold;
	}

	.btn {
		font-size: 16px;
		font-weight: 500;
		line-height: 24px;
		color: #fff;
		background-color: #3EC5DB;
		padding: 10px 23px;
		border-radius: 24px;
	}

	.noBtns {
		font-size: 16px;
		font-weight: 500;
		line-height: 24px;
		color: #666;
		background-color: #EBEBEB;
		padding: 10px 23px;
		border-radius: 24px;
	}

	.ft:before {
		content: '';
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		border-top: 1px solid rgba(0, 0, 0, 0.2);
		transform: scaleY(0.5);
	}
</style>